package card;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;


public class CardDemo {
    private final String[] suits = {"♥","♠","♦","♣"};
    public List<Card> ctrateCard(){
        List<Card> cardList = new ArrayList<>();
        for (int i = 0; i <4 ; i++) {
            for (int j = 1; j <=13; j++) {
                Card card = new Card(suits[i],j);
                cardList.add(card);
            }
        }
        return cardList;
    }
    public void shuffleCards(List<Card> cardList){
//        洗牌算法     要从后往前洗
        Random random = new Random();
        for (int i = cardList.size()-1;i > 0;i--){
            int index = random.nextInt(i);
            swap(cardList,i,index);
        }
    }
    public void swap (List<Card> cardList,int a, int b){
        Card temp = cardList.get(a);
        cardList.set(a,cardList.get(b));
        cardList.set(b,temp);
    }
}
